﻿function igtbl_editList(g, v, r, col, cElem) {
    var list = col.ValueList;
    if (list == null || list.length < 1) return null;
    var s, elem = g._editorList;


    var h = cElem.offsetHeight;
    if (!ig_csom.IsIE) {
        var i = cElem.childNodes.length;
        while (i-- > 0) {
            var curElem = cElem.childNodes[i];
            if (!g.getActiveCell().Element.Object.Row.IsFilterRow || curElem.tagName != "BUTTON") {
                if (curElem.style)
                    curElem.style.display = "none";
                else {
                    if (g._oldElems == null)
                        g._oldElems = new Array();
                    g._oldElems[g._oldElems.length] = curElem;
                    cElem.removeChild(curElem);
                }
            }
        }

    }

    if (elem == null) {
        g._editorList = elem = document.createElement("SELECT");

        if (!ig_csom.IsIE)
            cElem.appendChild(elem);
        else {
            document.body.insertBefore(elem, document.body.firstChild);
            elem.style.position = "absolute";
        }

        ig_csom.addEventListener(elem, "keydown", igtbl_editEvt);
        ig_csom.addEventListener(elem, "keyup", igtbl_editEvt);
        ig_csom.addEventListener(elem, "blur", igtbl_editEvt);
        ig_csom.addEventListener(elem, "mousedown", igtbl_listMouseDown);
        elem.style.zIndex = r.z;
        elem.setAttribute("editType", 3);
        elem.id = g.Id + "_vl";
        ig_csom.addEventListener(elem, "change", igtbl_dropDownChange);
    }

    else if (!ig_csom.IsIE)
        cElem.appendChild(elem);

    s = elem.style;
    var opt, css = col.ValueListClass;
    if (ig_csom.notEmpty(css))
        elem.className = css;
    else
        elem.style.fontSize = ((r.h -= 4) < 15) ? (((r.h < 9) ? 9 : r.h) + "px") : "";
    elem.value = v;
    var i = elem.options.length, prompt = col.ValueListPrompt;
    while (i-- > 0)
        elem.removeChild(elem.options[i]);
    if (ig_csom.notEmpty(prompt)) {
        elem.appendChild(opt = document.createElement("OPTION"));
        opt.text = opt.value = prompt;
    }
    while (++i < list.length) if (list[i] != null) {
        elem.appendChild(opt = document.createElement("OPTION"));
        opt.value = list[i][0];
        opt.text = list[i][1];


        if (v != null && (v == list[i][0])) { opt.selected = true; v = null; }
    }

    s.display = "";
    s.visibility = "hidden";

    eStyle = igtbl_getComputedStyle(elem);
    eStyle = igtbl_getComputedStyle(elem);
    cStyle = igtbl_getComputedStyle(cElem);

    if (g.IsXHTML) {
        var xd, yd, wd, hd;
        var cStyle, eStyle;
        if (ig_csom.IsIE) {
            eStyle = elem.currentStyle;
            cStyle = cElem.currentStyle;
            yd = Math.floor((igtbl_parseInt(cStyle.borderTopWidth) + igtbl_parseInt(cStyle.borderBottomWidth) + igtbl_parseInt(eStyle.borderTopWidth) + igtbl_parseInt(eStyle.borderBottomWidth)) / 2);
        }
        else {
            r.x--;
            r.y--;


            if (ig_csom.IsFireFox) {
                r.y -= g.DivElement.scrollTop;
                r.x -= g.DivElement.scrollLeft;
            }

            var pd = igtbl_parseInt(eStyle.paddingLeft);
            if (pd)
                r.w -= pd;
            pd = igtbl_parseInt(eStyle.paddingRight);
            if (pd)
                r.w -= pd;
            pd = igtbl_parseInt(eStyle.paddingTop);
            if (pd)
                r.h -= pd;
            pd = igtbl_parseInt(eStyle.paddingBottom);
            if (pd)
                r.h -= pd;
            pd = igtbl_parseInt(cStyle.paddingLeft);
            if (pd)
                r.w -= pd;
            pd = igtbl_parseInt(cStyle.paddingRight);
            if (pd)
                r.w -= pd;
            pd = igtbl_parseInt(cStyle.paddingTop);
            if (pd)
                r.h -= pd;
            pd = igtbl_parseInt(cStyle.paddingBottom);
            if (pd)
                r.h -= pd;
            r.h += 3;
            if (cElem.offsetHeight > h)
                r.h -= 2;

        }
        xd = igtbl_parseInt(eStyle.borderLeftWidth);
        if (xd)
            r.x -= Math.floor(xd / 2);
        if (yd)
            r.y += yd;
        wd = igtbl_parseInt(cStyle.borderLeftWidth) + igtbl_parseInt(cStyle.borderRightWidth);

        if (wd && ig_csom.IsIE)
            r.w += wd;
        wd = igtbl_parseInt(eStyle.borderLeftWidth);

        if (wd && ig_csom.IsIE)
            r.w += wd;
        if (hd)
            r.h += hd;
    }
    if (ig_csom.IsIE) {
        s.left = "0px";
        s.top = "0px";
    }
    s.left = r.x + "px";
    s.width = r.w + "px";

    if (!(g.IsXHTML && ig_csom.IsIE7)) {
        s.height = (cElem.offsetHeight - igtbl_parseInt(cStyle.borderTopWidth) - igtbl_parseInt(cStyle.borderBottomWidth)) + "px";
    }
    var so = igtbl_getStyleSheet(elem.className);
    if (so && so.verticalAlign == "top")
        s.top = r.y + "px";
    else if (so && so.verticalAlign == "bottom")
        s.top = r.y + r.h - elem.offsetHeight + "px";
    else
        s.top = r.y + r.h / 2 - elem.offsetHeight / 2 + "px";

    s.visibility = "visible";
    elem.focus();
    return elem;
}

// Overrides igtbl_dispose from ig_WebGrid.js to check obj.hasOwnProperty in order to correct a script error
// ("Unable to get value of the property 'init': object is null or undefined") in Internet Explorer 9 when interacting
// with the grid.  Infragistics corrects this in version 2010 with hotfix.
function igtbl_dispose(obj) {
    if (ig_csom.IsNetscape || ig_csom.IsNetscape6)
        return;
    for (var item in obj) {
        if (typeof (obj[item]) != "undefined" && obj[item] != null && !obj[item].tagName && !obj[item].disposing && typeof (obj[item]) != "string" && obj.hasOwnProperty(item)) {
            try {

                obj[item].disposing = true;
                igtbl_dispose(obj[item]);
            } catch (exc1) { ; }
        }
        try {
            delete obj[item];
        } catch (exc2) {
            return;
        }
    }
}
// Overrides Infragistics implementation to correctly support IE8
function igtree_toggle(tn, nodeId)
{
	var node=igtree_getNodeById(nodeId);
	var subnodes = igtree_getElementById("M_"+nodeId);
	var ts=igtree_treeState[tn];

	if(!node.getEnabled()) 
		return;
		
	// V20061
	if(!subnodes && (ts.LoadOnDemand == 1 || ts.LoadOnDemand == 2)) {
	// End V20061
		node.setExpanded(true);
		return;
	}
	if(subnodes != null) {
	    if(subnodes.style.display == "none") {
		    node.setExpanded(true);
	    }
	    else
		    node.setExpanded(false);
	}
	return;		
}
